<html>
<head><meta charset="utf-8"><title>inserting linker sections · wg-secure-code · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/index.html">wg-secure-code</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html">inserting linker sections</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="205427372"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205427372" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205427372">(Jul 29 2020 at 23:55)</a>:</h4>
<p><span class="user-mention" data-user-id="120823">@DPC</span> Actually, there is one instance where I could use some tips.<br>
I was looking into making a PoC implementation of <a href="https://github.com/rust-lang/rfcs/pull/2801">https://github.com/rust-lang/rfcs/pull/2801</a> (embed list of dependencies and their versions in binaries compiled via Cargo) and the necessary building block seems to be an unstable rustc flag that embeds a given file in the compiled binary via platform-specific mechanisms (EFL section, Mach-O, PE...).<br>
The only sane way I've found to do that was via objcopy (part of binutils), not via the linker itself. It seems like doing this via linker scripts should be possible, but I know nothing about them and the closest linker script example I found to "embed a file as a read-only section in the executable" is very convoluted.<br>
Any idea who might know more about the linking stage and could set me on the right path - i.e. either tell me to use objcopy or point me to linker script docs?</p>



<a name="205427628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205427628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> DPC <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205427628">(Jul 29 2020 at 23:59)</a>:</h4>
<p>you could try creating a thread in #t-compiler/help</p>



<a name="205427718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205427718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> DPC <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205427718">(Jul 30 2020 at 00:00)</a>:</h4>
<p>i may be wrong here but i think <code>@petrochenkov</code> generally deals with linking</p>



<a name="205428068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205428068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205428068">(Jul 30 2020 at 00:04)</a>:</h4>
<p><span class="user-mention" data-user-id="127617">@Shnatsel</span> I think we can probably just emit a static in the codegen step (or earlier, even) that just has the right value and is marked as used</p>



<a name="205428096"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205428096" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205428096">(Jul 30 2020 at 00:04)</a>:</h4>
<p>Would that not be sufficient? I guess some sort of LTO might remove it but maybe we can reference it in some way too</p>



<a name="205428493"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205428493" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205428493">(Jul 30 2020 at 00:09)</a>:</h4>
<p>I used the static+used trick in my initial prototype (<a href="https://github.com/Shnatsel/rust-audit">https://github.com/Shnatsel/rust-audit</a>) but that's a really ugly way to do that - I think it doesn't get its own section that way, and either way I have no control over the name of that section, so I had to use start/stop markers.<br>
Once I published that initial prototype, people pointed out that for ELF I could simply use objcopy, which is <em>way</em> cleaner:</p>
<div class="codehilite"><pre><span></span><code># Insert Cargo.lock into a new &#39;.dep-list&#39; section
objcopy --add-section .dep-list=Cargo.lock --set-section-flags .dep-list=noload,readonly mybinary mybinary.withdeps

# Extract Cargo.lock
objcopy -O binary --set-section-flags .dep-list=alloc --only-section=.dep-list mybinary.withdeps Cargo.lock.extracted
</code></pre></div>


<p>The best part is that it allows easy recovery of the data and I don't have to invent my own start/stop markers. So this is essentially what I want to achieve, eventually for all major platforms.</p>



<a name="205428630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205428630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Gaynor <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205428630">(Jul 30 2020 at 00:11)</a>:</h4>
<p><code>#[link_section = "blah"]</code> should let you control the section, right?</p>



<a name="205428720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205428720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205428720">(Jul 30 2020 at 00:12)</a>:</h4>
<p>I admit I am completely clueless here. But if that's all it takes then I'd <em>love</em> to do it this way since it would not even require any modifications to rustc, I could implement this as a crate</p>



<a name="205428749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205428749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205428749">(Jul 30 2020 at 00:13)</a>:</h4>
<p>Ah no, LTO would still remove it so I would need rustc to reference the static. But it's a step in the right direction.</p>



<a name="205428757"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205428757" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205428757">(Jul 30 2020 at 00:13)</a>:</h4>
<p><code>#[used]</code> is a thing</p>



<a name="205428773"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205428773" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205428773">(Jul 30 2020 at 00:13)</a>:</h4>
<p>though I have no idea how likely that is to still persist after LTO etc</p>



<a name="205428777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205428777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205428777">(Jul 30 2020 at 00:13)</a>:</h4>
<p><code>#[used]</code> is not sufficient, tried that already in <a href="https://github.com/Shnatsel/rust-audit">https://github.com/Shnatsel/rust-audit</a></p>



<a name="205428877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205428877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205428877">(Jul 30 2020 at 00:15)</a>:</h4>
<p>I am surprised linkers remove symbols in non-standard sections</p>



<a name="205428921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205428921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205428921">(Jul 30 2020 at 00:15)</a>:</h4>
<p>Ah, I haven't tried it with <em>non-standard section!</em> That's something I should check. Thanks for the tip!</p>



<a name="205430070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205430070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205430070">(Jul 30 2020 at 00:32)</a>:</h4>
<p><code>#[link_section = "blah"]</code> did something! The section now exists! Reading it and printing it out gives me <del>a short bit of junk</del> 2.3 Mb file instead of the string I've put in, <del>so assume it puts a pointer to the data in there instead of the actual data.</del> Code used:</p>
<div class="codehilite"><pre><span></span><code><span class="cp">#[link_section = </span><span class="s">&quot;.dep-list&quot;</span><span class="cp">]</span><span class="w"></span>
<span class="k">static</span><span class="w"> </span><span class="n">AUDITABLE_VERSION_INFO</span>: <span class="kp">&amp;</span><span class="nb">&#39;static</span><span class="w"> </span><span class="kt">str</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">include_str</span><span class="o">!</span><span class="p">(</span><span class="n">concat</span><span class="o">!</span><span class="p">(</span><span class="n">env</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;OUT_DIR&quot;</span><span class="p">),</span><span class="w"> </span><span class="s">&quot;/Cargo.lock.annotated&quot;</span><span class="p">));</span><span class="w"></span>
</code></pre></div>



<a name="205430156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205430156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Gaynor <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205430156">(Jul 30 2020 at 00:34)</a>:</h4>
<p>I think that's true. You can probably test that hypothesis by doing <code>#[link_section = ".dep-list"]  static AUDITABLE_VERSION_INFO: [u8; 10] = [something];</code> and if that gets the raw value, then the other thing is a ptr</p>



<a name="205430461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205430461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205430461">(Jul 30 2020 at 00:39)</a>:</h4>
<p>Hmm, no, something is off here. <code>#[link_section = ".dep-list"] static AUDITABLE_VERSION_INFO: [u8; 10] = [1,2,3,4,5,6,7,8,9,10];</code> gives me a 187kb file as output if extracted with <code>objcopy -O binary --set-section-flags .dep-list=alloc --only-section=.dep-list mybinary.withdeps Cargo.lock.extracted</code></p>



<a name="205430660"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205430660" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205430660">(Jul 30 2020 at 00:41)</a>:</h4>
<p>and I was wrong about the short bit of junk, the version with <code>include_str!</code> extracted via objcopy actually gives me a 2.3Mb file as the output</p>



<a name="205430769"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205430769" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205430769">(Jul 30 2020 at 00:43)</a>:</h4>
<p>2.3Mb is bigger than the entire executable it was extracted from, which is 1.1Mb... weird</p>



<a name="205430894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205430894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205430894">(Jul 30 2020 at 00:45)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span>  <code>#[used] #[link_section = ".dep-list"] &amp;'static str</code> does not survive LTO</p>



<a name="205430991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205430991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205430991">(Jul 30 2020 at 00:47)</a>:</h4>
<p>That is surprising! Maybe we're not sufficiently marking it as used or something</p>



<a name="205431233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205431233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205431233">(Jul 30 2020 at 00:52)</a>:</h4>
<p>Yes, <code>#[used]</code> doesn't go far enough. The only thing that I could make reliably work is inserting a call to this in <code>fn main()</code>:</p>
<div class="codehilite"><pre><span></span><code><span class="cp">#[inline(always)]</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">annotate_this_executable</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">test</span>::<span class="n">black_box</span><span class="p">(</span><span class="n">AUDITABLE_VERSION_INFO</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p>where <code>AUDITABLE_VERSION_INFO</code> is the <code>&amp;'static str</code> I want to preserve</p>



<a name="205431252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205431252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205431252">(Jul 30 2020 at 00:52)</a>:</h4>
<p>LTO is too good at its job</p>



<a name="205431466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205431466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205431466">(Jul 30 2020 at 00:56)</a>:</h4>
<p>Ah! Got it! So this does indeed return 10 bytes: <code>#[link_section = ".dep-list"] static AUDITABLE_VERSION_INFO: [u8; 10] = [1,2,3,4,5,6,7,8,9,10];</code><br>
if extracted with <code>objcopy -O binary --only-section=.dep-list target/release/hello-auditable Cargo.lock.extracted</code><br>
Doing this to a <code>&amp;'static str</code> returns 16 bytes<br>
Now the question is, how do I embed the <code>&amp;'static str</code> as inline data instead of a pointer</p>



<a name="205431694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205431694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Gaynor <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205431694">(Jul 30 2020 at 01:01)</a>:</h4>
<p>Let me know if you figure it out! <a href="https://github.com/fishinabarrel/linux-kernel-module-rust/blob/master/src/lib.rs#L78-L81">https://github.com/fishinabarrel/linux-kernel-module-rust/blob/master/src/lib.rs#L78-L81</a></p>



<a name="205431697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205431697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205431697">(Jul 30 2020 at 01:01)</a>:</h4>
<p>The naive version fails:</p>
<div class="codehilite"><pre><span></span><code>6 | static AUDITABLE_VERSION_INFO: str = include_str!(concat!(env!(&quot;OUT_DIR&quot;), &quot;/Cargo.lock.annotated&quot;));
  |                                ^^^ doesn&#39;t have a size known at compile-time
</code></pre></div>



<a name="205431759"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205431759" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Gaynor <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205431759">(Jul 30 2020 at 01:02)</a>:</h4>
<p><code>static FOO: [u8; include_bytes!(...).len()] = include_bytes!(...);</code> is the net thing I'd try, but I bet it doesn't work</p>



<a name="205431928"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205431928" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205431928">(Jul 30 2020 at 01:06)</a>:</h4>
<p>I think it worked... 285 bytes now</p>



<a name="205431939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205431939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205431939">(Jul 30 2020 at 01:06)</a>:</h4>
<p>I CANNOT BELIEVE IT ACTUALLY WORKED</p>



<a name="205431945"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205431945" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Gaynor <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205431945">(Jul 30 2020 at 01:06)</a>:</h4>
<p>Typing nonsense is my specialty</p>



<a name="205431946"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205431946" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205431946">(Jul 30 2020 at 01:06)</a>:</h4>
<p>All hail const fn and const generics</p>



<a name="205431950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205431950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Gaynor <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205431950">(Jul 30 2020 at 01:07)</a>:</h4>
<p>This isn't const generics!</p>



<a name="205431959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205431959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205431959">(Jul 30 2020 at 01:07)</a>:</h4>
<p>It is const generics MVP so I could use <code>[u8; 285]</code></p>



<a name="205431964"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205431964" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205431964">(Jul 30 2020 at 01:07)</a>:</h4>
<p>(deleted)</p>



<a name="205432569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205432569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205432569">(Jul 30 2020 at 01:21)</a>:</h4>
<p><a href="https://github.com/Shnatsel/rust-audit">https://github.com/Shnatsel/rust-audit</a> updated with <code>#[link_section = ".rust-audit-dep-list"]</code> so it can also be extracted via <code>objcopy</code></p>



<a name="205432873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205432873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205432873">(Jul 30 2020 at 01:28)</a>:</h4>
<p>And it even survives LTO without ugly hacks!</p>



<a name="205433050"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205433050" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205433050">(Jul 30 2020 at 01:33)</a>:</h4>
<p>Wow. Thanks a lot! It's starting to look like <a href="https://github.com/rust-lang/rfcs/pull/2801">https://github.com/rust-lang/rfcs/pull/2801</a> is going to be actually practical to implement as a crate now!</p>



<a name="205435114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205435114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Gaynor <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205435114">(Jul 30 2020 at 02:13)</a>:</h4>
<p>Oh gosh that <code>build.rs</code> <code>../../../..</code></p>



<a name="205435197"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205435197" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205435197">(Jul 30 2020 at 02:14)</a>:</h4>
<p>Is that bad?</p>



<a name="205435240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205435240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Gaynor <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205435240">(Jul 30 2020 at 02:15)</a>:</h4>
<p>Well, it relies on an assumption about where <code>OUT_DIR</code> is relative to the project, so if you use <code>CARGO_TARGET_DIR</code>, it'd break, right?</p>



<a name="205435301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205435301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205435301">(Jul 30 2020 at 02:16)</a>:</h4>
<p>Frankly I have no clue, this is a proof-of-concept implementation and I didn't actually look up the docs for the variables I used</p>



<a name="205435317"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205435317" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205435317">(Jul 30 2020 at 02:16)</a>:</h4>
<p>I would however very much welcome input on it since I'm trying to turn it into a full-fledged implementation</p>



<a name="205435407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205435407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205435407">(Jul 30 2020 at 02:18)</a>:</h4>
<p>If <code>OUT_DIR</code> can be set to an arbitrary location then the entire idea of using it to locate <code>Cargo.lock</code> is a bust, and I need some other approach...</p>



<a name="205435524"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205435524" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205435524">(Jul 30 2020 at 02:20)</a>:</h4>
<p>Let's see if <code>CARGO_MANIFEST_DIR</code> does the job</p>



<a name="205435700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205435700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205435700">(Jul 30 2020 at 02:24)</a>:</h4>
<p>Nope. The problem with <code>CARGO_MANIFEST_DIR</code> is that when accesses from <code>build.rs</code> it is set to the crate where <code>build.rs</code> is run; so users of the crate would have to modify their own <code>build.rs</code> for this to work</p>



<a name="205435735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205435735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205435735">(Jul 30 2020 at 02:25)</a>:</h4>
<p>Which is not the end of the world, but I would prefer adding the dependency on <code>auditable</code> to be sufficient to get the executable annotated</p>



<a name="205435820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205435820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205435820">(Jul 30 2020 at 02:27)</a>:</h4>
<p>Oh well, perhaps it is for the best - allows finer-grained control and all that</p>



<a name="205464073"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205464073" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205464073">(Jul 30 2020 at 10:48)</a>:</h4>
<p>That is surprising! Maybe we're not sufficiently marking it as used or something</p>



<a name="205469874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205469874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205469874">(Jul 30 2020 at 12:09)</a>:</h4>
<p>There is an open issue about <code>#[used]</code> not being sufficient in this case: <a href="https://github.com/rust-lang/rust/issues/47384">https://github.com/rust-lang/rust/issues/47384</a></p>



<a name="205635485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205635485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205635485">(Jul 31 2020 at 20:00)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> so apparently <code>#[used]</code> not working properly is a known bug, and it's quite old: <a href="https://github.com/rust-lang/rust/issues/47384">https://github.com/rust-lang/rust/issues/47384</a><br>
Using <code>#[link_section = "foo"]</code> doesn't preserve the static either.</p>



<a name="205636282"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205636282" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205636282">(Jul 31 2020 at 20:08)</a>:</h4>
<p>/me is quite confused by linkers removing <em>unknown</em> data</p>



<a name="205636287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205636287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205636287">(Jul 31 2020 at 20:08)</a>:</h4>
<p>that just seems crazy</p>



<a name="205636310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205636310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205636310">(Jul 31 2020 at 20:08)</a>:</h4>
<p>I guess -- one other thing we could try -- is to attach the data as DWARF or something</p>



<a name="205636319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205636319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205636319">(Jul 31 2020 at 20:08)</a>:</h4>
<p>but that is... questionable</p>



<a name="205637242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205637242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205637242">(Jul 31 2020 at 20:18)</a>:</h4>
<p>maybe we can look at sources for gcc or something like that and figure out what conditions things are retained under</p>



<a name="205637998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205637998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205637998">(Jul 31 2020 at 20:26)</a>:</h4>
<p>I suspect that because of that bug my<code>#[used]</code> static doesn't even reach the linker</p>



<a name="205639166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205639166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205639166">(Jul 31 2020 at 20:39)</a>:</h4>
<p><span class="user-mention" data-user-id="127617">@Shnatsel</span> that bug feels fixable to me, but I've not touched that part of the compiler in a while</p>



<a name="205693132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205693132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205693132">(Aug 01 2020 at 18:37)</a>:</h4>
<p><span class="user-mention" data-user-id="127617">@Shnatsel</span> have you checked out <a href="https://github.com/lukaslueg/built">https://github.com/lukaslueg/built</a> ?</p>



<a name="205696713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205696713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205696713">(Aug 01 2020 at 20:20)</a>:</h4>
<p>No, thanks for the pointer! I was also pointed to <a href="https://github.com/danielschemmel/build-info">https://github.com/danielschemmel/build-info</a> yesterday</p>



<a name="205696790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205696790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205696790">(Aug 01 2020 at 20:22)</a>:</h4>
<p><span class="user-mention" data-user-id="132721">@Tony Arcieri</span> Also I think I've managed to build the JSON serialization/parsing in a separate crate and interoperate with <code>cargo-lock</code> via <code>From</code>/<code>TryInto</code>. <br>
I see <code>checksum</code> field is optional, could you explain under what conditions it may be missing? In V1 format where it's stored in metadata, will it be copied into the struct or not?</p>



<a name="205697057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205697057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205697057">(Aug 01 2020 at 20:30)</a>:</h4>
<p>I believe it should be but I’m not at a computer ATM</p>



<a name="205697062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205697062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205697062">(Aug 01 2020 at 20:31)</a>:</h4>
<p>the crate tries to provide a unified representation across the two formats</p>



<a name="205697080"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205697080" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205697080">(Aug 01 2020 at 20:31)</a>:</h4>
<p>Excellent</p>



<a name="205700498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205700498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205700498">(Aug 01 2020 at 22:18)</a>:</h4>
<p>Initial JSON format convertible to/from Cargo.lock via <code>cargo-lock</code> crate: <a href="https://github.com/Shnatsel/rust-audit/tree/master/auditable-serde">https://github.com/Shnatsel/rust-audit/tree/master/auditable-serde</a></p>



<a name="205702190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205702190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205702190">(Aug 01 2020 at 23:15)</a>:</h4>
<p>I'll wire it up to <code>auditable</code> tomorrow so that it would embed this JSON we could later stabilize instead of unstable Cargo.lock</p>



<a name="205702243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205702243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205702243">(Aug 01 2020 at 23:16)</a>:</h4>
<p>After that the only remaining piece is the cross-platform extractor of this data from the compiled binary, and waiting for 1.46 for loops in <code>const fn</code> to reach stable</p>



<a name="205849369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205849369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205849369">(Aug 03 2020 at 21:28)</a>:</h4>
<p>Side effect of <code>auditable</code> development: <a href="https://github.com/Frommi/miniz_oxide/pull/88">https://github.com/Frommi/miniz_oxide/pull/88</a><br>
<code>Add support for limiting output size when decompressing to Vec</code></p>



<a name="205921833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/205921833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#205921833">(Aug 04 2020 at 15:29)</a>:</h4>
<p><span class="user-mention" data-user-id="132721">@Tony Arcieri</span> I'm adding you as uploader for <code>auditable</code> crate to increase bus factor</p>



<a name="206408479"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/206408479" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#206408479">(Aug 09 2020 at 19:28)</a>:</h4>
<p>Speaking of <a href="https://github.com/rust-lang/rfcs/pull/2801">https://github.com/rust-lang/rfcs/pull/2801</a> again:<br>
Can anyone see a reason to embed package hash for packages that came from a registry? Hashes are not compressible and so bloat the info quite a bit (they make up &gt;80% of the data), plus I just can't come up with a use case for them</p>



<a name="206408932"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/206408932" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#206408932">(Aug 09 2020 at 19:42)</a>:</h4>
<p>I guess if the hashes are not included one has to trust the registry to be able to check that the package content is still what it used to be</p>



<a name="206409085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/206409085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#206409085">(Aug 09 2020 at 19:47)</a>:</h4>
<p>Yeah, but if your registry was compromised and you got a malicious package, the malicious package could lie about its hash because it literally has arbitrary code execution through <a href="http://build.rs">build.rs</a></p>



<a name="206409145"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/206409145" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#206409145">(Aug 09 2020 at 19:49)</a>:</h4>
<p>Hashes are useful for Cargo.lock where it can reject a download with a the mismatch in the hash, but not in the compiled executable. Or at least the way I see it, I do want people to challenge this view</p>



<a name="206411095"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/206411095" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#206411095">(Aug 09 2020 at 20:49)</a>:</h4>
<p>A <a href="http://build.rs">build.rs</a> script can also cause a different crate name to be embedded.</p>



<a name="206416797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/206416797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#206416797">(Aug 09 2020 at 23:38)</a>:</h4>
<p>Indeed. Once you have downloaded a malicious dependency, it can lie in arbitrary ways since it can execute arbitrary code and has write access to the resulting binary</p>



<a name="206419541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/206419541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#206419541">(Aug 10 2020 at 00:59)</a>:</h4>
<p>having the package hash at least makes that <a href="http://build.rs">build.rs</a> script correlatable and auditable</p>



<a name="206419546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/206419546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tony Arcieri <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#206419546">(Aug 10 2020 at 00:59)</a>:</h4>
<p>also ideally they could be better sandboxed</p>



<a name="206525557"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/206525557" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#206525557">(Aug 10 2020 at 23:35)</a>:</h4>
<p>Status update: I now have a full pipeline for embedding dependency info in compiled executable, including the dependency graph and dependency type (build/runtime), all below 1% of the executable size (or below 0.1% without the hashes).<br>
The extractor for this data in Rust is not yet public, I'm awaiting legal clearance, but it can be substituted with a shell one-liner. The rest is public at <a href="https://github.com/Shnatsel/rust-audit">https://github.com/Shnatsel/rust-audit</a><br>
But the more I work on this, the more there is to do.</p>



<a name="206583654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/206583654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#206583654">(Aug 11 2020 at 14:43)</a>:</h4>
<p>Binary parser is now public: <a href="https://github.com/Shnatsel/binfarce">https://github.com/Shnatsel/binfarce</a><br>
Now that <code>binfarce</code> is public, I've added the extraction pipeline to <a href="https://github.com/Shnatsel/rust-audit">https://github.com/Shnatsel/rust-audit</a> repo</p>



<a name="206583701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/206583701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#206583701">(Aug 11 2020 at 14:43)</a>:</h4>
<p>It should be fully functional for ELF</p>



<a name="206589305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/206589305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#206589305">(Aug 11 2020 at 15:26)</a>:</h4>
<p>The documentation is not up to date - I've had to change the interfaces a few times, I'd rather not waste a lot of effort documenting them before I freeze them</p>



<a name="206618674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146229-wg-secure-code/topic/inserting%20linker%20sections/near/206618674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/146229-wg-secure-code/topic/inserting.20linker.20sections.html#206618674">(Aug 11 2020 at 19:17)</a>:</h4>
<p>The conversion to <code>cargo-lock</code> data structures is also implemented now</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>